home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / C / KBIRS.ZIP / KEY.C next >
Encoding:
C/C++ Source or Header  |  1995-06-29  |  2.0 KB  |  80 lines

  1. /*
  2.             Keys : A demomstration program using my KEYBOARD.C lib.
  3.             Copyright (c) 1995 by Mark C. Williston.
  4.             EMAIL: mwillist@fox.nstn.ca
  5.             Released to the PUBLIC DOMAIN which can be used in any way
  6.             or place you see fit.
  7.             I hope it help anyone! Mail me if it does.
  8. */
  9.  
  10. #include <dos.h>
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include "keyboard.h"
  14.  
  15. #define TRUE 1
  16. #define FALSE 0
  17.  
  18.  
  19. unsigned char ScanCode;         // Scan code of the last key pressed
  20. unsigned char KeyTable[128];    // Table for holding key presses
  21. unsigned char KeyboardStatus=0; // Hold LED status
  22.  
  23.  
  24. void    main(void)
  25. {
  26.  
  27.     int done=FALSE, n;
  28.     unsigned char OldKey=0;    // Used to compare old and new keys
  29.  
  30.     _setcursortype(_NOCURSOR); // Turn off the cursor
  31.     clrscr();
  32.     BuildTemplate();
  33.     InstallKeyboardInt();
  34.  
  35.     while(!done)
  36.     {
  37.         if(OldKey != ScanCode)
  38.         {
  39.             OldKey=ScanCode;
  40.             DoKeys();
  41.             if(ScanCode==1)
  42.             {
  43.                 done=1;
  44.                 while(ScanCode==1);
  45.             }
  46.             if(ScanCode==58)  // Was the CAPS LOCK Pressed?
  47.             {
  48.                 KeyboardStatus^=4;  // Toggle CAPS bit
  49.                 KeyboardCommand(0xed, KeyboardStatus); // Send STATUS WRITE command
  50.                 FlipLites(1);
  51.             }
  52.             if(ScanCode==69)  // Was the NUM LOCK Pressed?
  53.             {
  54.                 KeyboardStatus^=2;  // Toggle NUM LOCK bit
  55.                 KeyboardCommand(0xed, KeyboardStatus); // Send STATUS WRITE command
  56.                 FlipLites(0);
  57.             }
  58.             if(ScanCode==70)  // Was the SCROLL LOCK Pressed?
  59.             {
  60.                 KeyboardStatus^=1;  // Toggle SCROLL LOCK bit
  61.                 KeyboardCommand(0xed, KeyboardStatus); // Send STATUS WRITE command
  62.                 FlipLites(2);
  63.             }
  64.         }
  65.     }
  66.  
  67.     KeyboardStatus=4; // Start off at Bit 2
  68.     for(n=0; n<30; n++)  // Rotate LEDs just for the heck of it.
  69.     {
  70.         KeyboardCommand(0xed, KeyboardStatus); // Send STATUS WRITE command
  71.         KeyboardStatus>>=1;  // Shift LED bit
  72.         if(KeyboardStatus==0) KeyboardStatus=4; // Back to Bit 2
  73.         delay(100);
  74.     }
  75.  
  76.     RestoreKeyboardInt();  // Give old Keyboard ISR back to MessyDos
  77.     _setcursortype(_NORMALCURSOR); /* Switch back to the normal cursor */
  78.     clrscr(); // Clear our garbage off screen
  79.  
  80. }